package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsKeywordMapper;
import com.qf.pojo.DtsKeyword;
import com.qf.service.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 22:22
 */
@Service
public class KeywordServiceImpl implements KeywordService {

    @Autowired
    private DtsKeywordMapper dtsKeywordMapper;
    @Override
    public IPage<DtsKeyword> findListByQuery(Integer page, Integer limit, String sort, String order, String keyword, String url) {
        return dtsKeywordMapper.selectPage(new Page<DtsKeyword>(page,limit)
                ,new QueryWrapper<DtsKeyword>()
                        .like(!StringUtils.isEmpty(keyword),"keyword",keyword)
                        .eq(!StringUtils.isEmpty(url),"url",url)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort)
        );
    }

    @Override
    public DtsKeyword create(DtsKeyword dtsKeyword) {
        dtsKeywordMapper.insert(dtsKeyword);
        return dtsKeyword;
    }

    @Override
    public DtsKeyword update(DtsKeyword dtsKeyword) {
        dtsKeywordMapper.updateById(dtsKeyword);
        return dtsKeyword;
    }

    @Override
    public DtsKeyword delete(DtsKeyword dtsKeyword) {
        dtsKeywordMapper.deleteById(dtsKeyword);
        return dtsKeyword;
    }
}
